#郑文超

import time,os
from PIL import ImageGrab
from selenium import webdriver
from common.login import Login
from selenium.webdriver.support.select import Select
import random
from testcase.zwc_read_excel import *


class financial_flow:
    def __init__(self,username,big_module,small_module):
        self.st = Login()
        self.driver = self.st.driver
        self.st.login_user(username)
        self.st.open_module(big_module,small_module)

    #区域下拉框
    def region(self):
        return self.driver.find_element_by_name("region")

    #收支类别下拉框
    def type(self):
        return self.driver.find_element_by_name("type")

    # 一级科目下拉框
    def first_subject(self):
        return self.driver.find_element_by_name("first_subject")

     # 二级科目下拉框
    def second_subject(self):
        return  self.driver.find_element_by_name("second_subject")

    # 账户下拉框
    def account(self):
        return self.driver.find_element_by_name("account")

    # 审核状态下拉框
    def status(self):
        return  self.driver.find_element_by_name("status")

    # 开始时间
    def s_time(self):
        self.driver.find_element_by_name("s_time").clear()
        return self.driver.find_element_by_name("s_time")

    # 结束时间
    def e_time(self):
        self.driver.find_element_by_name("e_time").clear()
        return self.driver.find_element_by_name("e_time")

    #收支类型
    def types(self):
        return self.st.driver.find_element_by_xpath('//*[@id="subjectInfo"]/div[1]/div/select')

    # 查询按钮
    def check(self):
        return self.driver.find_element_by_xpath("/html/body/div[7]/div[2]/div/div/div[2]/button")

    # 审核状态下拉框
    def approval(self):
        return self.driver.find_element_by_xpath("/html/body/div[7]/div[2]/div/div/div[2]/select")

    #通过按钮
    def dopass(self):
        return self.driver.find_element_by_xpath("/html/body/div[7]/div[2]/div/div/div[3]/div[2]/div[2]/table/tbody/tr[1]/td[13]/button")

    #系统提示对话框
    def alert_window(self):
        return self.driver.find_element_by_xpath("/html/body/div[11]/div/div/div[3]/button")

    #第一个展开按钮
    def open(self):
        return self.driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='操作'])[1]/following::i[1]").click()

    #获取下拉框所有选项
    def random_select(self,foo,text):
        wd = Select(foo)  #实例化一个下拉框
        # options = wd.options  #返回所有选项
        # random_index = random.randint(1,len(options)-1) #随机获得一个下标
        # print(random_index)   #打印下标
        # # wd.select_by_index(random_index)
        # random_text = options[random_index].text
        # wd.select_by_visible_text(random_text)
        # print(random_text)
        wd.select_by_visible_text(text)

    #截图
    def screenshot(self):
        pic_path = "../report/"
        filename = time.strftime('%Y%m%d_%H%M%S.png')
        ImageGrab.grab().save(pic_path + filename)
        return filename

    #添加收入
    def add_income(self):
        return self.driver.find_element_by_xpath("/html/body/div[7]/div[2]/div/div/div[2]/div[1]/button[1]")
    #添加支出
    def addExpend(self):
        return self.driver.find_element_by_xpath("/html/body/div[7]/div[2]/div/div/div[2]/div[1]/button[2]")
    #添加内部流转
    def addinner(self):
        return self.driver.find_element_by_xpath("/html/body/div[7]/div[2]/div/div/div[2]/div[1]/button[3]")
    #关闭对话窗口
    def window(self):
        return self.driver.find_element_by_xpath("/html/body/div[16]/div/div/div[1]/button/span[1]")

if __name__ == '__main__':
    start = financial_flow()
    # start.screenshot()
    # time.sleep(3)
    # start.random_select(start.account())
    # time.sleep(2)
    # start.random_select(start.approval())
    # start.random_select(start.first_subject(),"主营业务收入")
    # start.add_income().click()
    # start.window().click()
    # start.addExpend().click()
